package com.hexus.eve.entities;

import java.util.Locale;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.hexus.eve.utils.BlueprintUtils;
import com.hexus.eve.utils.TranslationUtils;

@Entity
@Table(name="invTypes")
public class Type extends EveEntity {
	private static final String DB_TABLE_NAME = "dbo.invTypes";
	private static final String NAME_COLUMN = "typeName";
	private static final String DESCRIPTION_COLUMN = "description";
	
	@Id	
	@Column(name="typeID")
	private Integer id;
	
	@Column(name="typeName")
	private String name;
	
	@ManyToOne
	@JoinColumn(name="groupID")
	private Group group;
	
	private String description;
	private Integer graphicID;
	private Float radius;
	private Float mass;
	private Float volume;
	private Float capacity;
	private Integer portionSize;
	
	@ManyToOne
	@JoinColumn(name="raceID")
	private Race race;
	
	private Float basePrice;
	private Boolean published;
	
	@ManyToOne
	@JoinColumn(name="marketGroupID")
	private MarketGroup marketGroup;
	
	private Float chanceOfDuplicating;
	
	@ManyToOne
	@JoinColumn(name="iconID")
	private Icon icon;

	public void setId(Integer id) {
		this.id = id;
	}

	public Race getRace() {
		return race;
	}

	public void setRace(Race race) {
		this.race = race;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getId() {
		return id;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Integer getGraphicID() {
		return graphicID;
	}

	public void setGraphicID(Integer graphicID) {
		this.graphicID = graphicID;
	}

	public Float getRadius() {
		return radius;
	}

	public void setRadius(Float radius) {
		this.radius = radius;
	}

	public Float getMass() {
		return mass;
	}

	public void setMass(Float mass) {
		this.mass = mass;
	}

	public Float getVolume() {
		return volume;
	}

	public void setVolume(Float volume) {
		this.volume = volume;
	}

	public Float getCapacity() {
		return capacity;
	}

	public void setCapacity(Float capacity) {
		this.capacity = capacity;
	}

	public Integer getPortionSize() {
		return portionSize;
	}

	public void setPortionSize(Integer portionSize) {
		this.portionSize = portionSize;
	}

	public Float getBasePrice() {
		return basePrice;
	}

	public void setBasePrice(Float basePrice) {
		this.basePrice = basePrice;
	}

	public Boolean getPublished() {
		return published;
	}

	public void setPublished(Boolean published) {
		this.published = published;
	}

	public Float getChanceOfDuplicating() {
		return chanceOfDuplicating;
	}

	public void setChanceOfDuplicating(Float chanceOfDuplicating) {
		this.chanceOfDuplicating = chanceOfDuplicating;
	}


	public Icon getIcon() {
		return icon;
	}

	public void setIcon(Icon icon) {
		this.icon = icon;
	}

	public MarketGroup getMarketGroup() {
		return marketGroup;
	}

	public void setMarketGroup(MarketGroup marketGroup) {
		this.marketGroup = marketGroup;
	}

	public Group getGroup() {
		return group;
	}

	public void setGroup(Group group) {
		this.group = group;
	}

	@Override
	public String getTableName() {		
		return DB_TABLE_NAME;
	}

	@Override
	public void translate(Map<String, String> translationValues, Locale locale) {
		if(translationValues.containsKey(NAME_COLUMN)) {
			setName(translationValues.get(NAME_COLUMN));
		}	
		if(translationValues.containsKey(DESCRIPTION_COLUMN)) {
			setDescription(translationValues.get(DESCRIPTION_COLUMN));
		}
		TranslationUtils.getInstance().translate(group, locale);	
		TranslationUtils.getInstance().translate(marketGroup, locale);
	}
	
	public Boolean isBlueprint() {
		return BlueprintUtils.getInstance().isBlueprint(this);		
	}
}